package cn.tsoft.taobao.util;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

public class StreamTool {
	public static byte[] readInputStream(InputStream inStream) throws Exception{
		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		int len = 0;
		while( (len=inStream.read(buffer)) != -1 ){
			outStream.write(buffer, 0, len);
		}
		inStream.close();
		return outStream.toByteArray();
	}
	
	public static String readInputStringStream(InputStream inStream) throws Exception{
		StringBuffer sb = new StringBuffer();
		String line = null;
		BufferedReader buffer = new BufferedReader(new InputStreamReader(inStream));
		while ((line = buffer.readLine()) != null) {
			sb.append(line);
		}
		return sb.toString();
	}
}
